//
//  MainViewController.m
//  HikingManagerRemake
//
//  Created by FENGYL on 2016/12/26.
//  Copyright © 2016年 FENGYL. All rights reserved.
//

#import "MainViewController.h"
#import "UIView+XL.h"
#import "CoverViewController.h"
#import <MBProgressHUD.h>
#import "UIView+badge.h"
#import "UserModel.h"
#import "ChatViewController.h"
#import <AudioToolbox/AudioToolbox.h>
#import <CoreLocation/CoreLocation.h>

static NSString * cellIdentifier = @"MainCellIdentifier";

@interface MainViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UIButton *smallMenuButton;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (strong , nonatomic) UIView * smallMenuView;
@property (strong , nonatomic) CoverViewController * coverViewController;
@property (strong , nonatomic) NSMutableArray * dataArray;

@property (strong , nonatomic) UserModel * userModel;

@property (assign , nonatomic) BOOL unread;

@end

@implementation MainViewController

-(CoverViewController *)coverViewController{
    if (!_coverViewController) {
        _coverViewController = [[CoverViewController alloc]init];
    }
    return _coverViewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.tableFooterView = [[UIView alloc]init];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.coverViewController.smallMenuHidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 弹出菜单
- (IBAction)smallMenuButton:(id)sender {
    
    if (self.coverViewController.smallMenuHidden) {
        
        UIWindow * window = [UIApplication sharedApplication].keyWindow;
        
        self.coverViewController = [[CoverViewController alloc]init];
        
        self.coverViewController.view.frame = window.bounds;
        
        UIImage * image = [UIImage imageNamed:@"hk_short_bg"];
        
        self.smallMenuView = [[UIView alloc]init];
        
        self.smallMenuView.size = CGSizeMake(130, 210);
        
        self.smallMenuView.layer.contents = (__bridge id _Nullable)(image.CGImage);
        
        CGFloat x = [UIScreen mainScreen].bounds.size.width - 135;
        
        CGFloat y = CGRectGetMaxY(self.smallMenuButton.frame) - self.smallMenuView.size.height - self.smallMenuButton.size.height -20;
        
        self.smallMenuView.x = x;
        
        self.smallMenuView.y = y;
        
        [self setUpSmallMenuViewButton];
        
        [self.coverViewController.view addSubview:self.smallMenuView];
        
        [window addSubview:self.coverViewController.view];
        
    }
    
    
}

#pragma mark 设置SmallMenu按钮
-(void)setUpSmallMenuViewButton{
    
    //SOS
    UIButton * sosButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    sosButton.frame = CGRectMake(0, 0, 130, 50);
    
    [sosButton setTitle:@"SOS" forState:UIControlStateNormal];
    
    [sosButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [sosButton setImage:[UIImage imageNamed:@"menu_short_sos"] forState:UIControlStateNormal];
    
    [sosButton setImageEdgeInsets:UIEdgeInsetsMake(0, sosButton.imageView.width - sosButton.titleLabel.x, 0, 0)];
    
    [self.smallMenuView addSubview:sosButton];
    
    
    //Public Chat
    
    UIButton * publicChat = [UIButton buttonWithType:UIButtonTypeCustom];
    
    publicChat.frame = CGRectMake(0, 50, 130, 50);
    
    [publicChat setTitle:@"Public Chat" forState:UIControlStateNormal];
    
    [publicChat setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [publicChat setImage:[UIImage imageNamed:@"menu_short_public"] forState:UIControlStateNormal];
    
    [publicChat setImageEdgeInsets:UIEdgeInsetsMake(0, publicChat.imageView.width - publicChat.titleLabel.x, 0, 0)];
    
//    [publicChat addTarget:self action:@selector(publicChatEvent) forControlEvents:UIControlEventTouchUpInside];
    
    [self.smallMenuView addSubview:publicChat];
    
    
    //Group Chat
    
    UIButton * groupChat = [UIButton buttonWithType:UIButtonTypeCustom];
    
    groupChat.frame = CGRectMake(0, 100, 130, 50);
    
    [groupChat setTitle:@"Group Chat" forState:UIControlStateNormal];
    
    [groupChat setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [groupChat setImage:[UIImage imageNamed:@"menu_short_group"] forState:UIControlStateNormal];
    
    [groupChat setImageEdgeInsets:UIEdgeInsetsMake(0, groupChat.imageView.width - groupChat.titleLabel.x, 0, 0)];
    
//    [groupChat addTarget:self action:@selector(groupChatEvent) forControlEvents:UIControlEventTouchUpInside];
    
    [self.smallMenuView addSubview:groupChat];
    
    //1-to-1 Chat
    
    UIButton * oneToOneChat = [UIButton buttonWithType:UIButtonTypeCustom];
    
    oneToOneChat.frame = CGRectMake(0, 150, 130, 50);
    
    [oneToOneChat setTitle:@"1-to-1 Chat" forState:UIControlStateNormal];
    
    [oneToOneChat setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [oneToOneChat setImage:[UIImage imageNamed:@"menu_short_single"] forState:UIControlStateNormal];
    
    [oneToOneChat setImageEdgeInsets:UIEdgeInsetsMake(0, oneToOneChat.imageView.width - oneToOneChat.titleLabel.x, 0, 0)];
    
//    [oneToOneChat addTarget:self action:@selector(oneToOneChatEvent) forControlEvents:UIControlEventTouchUpInside];
    
    [self.smallMenuView addSubview:oneToOneChat];
    
    
}

#pragma mark TableView
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        
    }
    
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    
    ChatViewController * chatViewController = [storyboard instantiateViewControllerWithIdentifier:@"ChatViewController"];
    
    [self showViewController:chatViewController sender:nil];
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
